/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dp1.pucp.Logistica.Vista;

import com.dp1.pucp.Modelo.Clases.*;
import java.awt.event.ActionListener;
import com.dp1.pucp.Util.Validaciones;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JFrame;
/**
 *
 * @author jorge
 */
public class PedidoProduccionGUI extends javax.swing.JDialog {
    
    /**
     * Creates new form UsuarioGUI
     * 
     * 
     */
     public Tipoproducto tipoproducto = new Tipoproducto();
     private JFrame padre;
    
    
    public PedidoProduccionGUI(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        txtCodigoProd.setVisible(false);
        setLocationRelativeTo(null);
    }

    public void setFormUsuario(Tipoproducto u){
        if (u!=null){
            
            txtProducto.setText(u.getNombre());
            txtCantidad.setText(u.getMaxPolitica().toString());
            
            
            //if(u.getTipo().equals("MP")){
              //  cmbTurno.setSelectedIndex(0);
            //}
            //if(u.getTipo().equals("PF")){
              //  cmbTurno.setSelectedIndex(1);
            //}
            //if(u.getTipo().equals("PI")){
              //  cmbTurno.setSelectedIndex(2);
            //}
            
            tipoproducto=u;
        }
    }
    
     public void setFormUsuarioSimu(Simulacion u){
        if (u!=null){
            
            txtSimulacion.setText(String.valueOf(u.getIdsimulacion()));
            //txtCantidad.setText(u.getMaxPolitica().toString());
            
            if(u.getTurno()==1){
                cmbTurno.setSelectedIndex(0);
            }
            if(u.getTurno()==2){
                cmbTurno.setSelectedIndex(1);
            }
            if(u.getTurno()==3){
                cmbTurno.setSelectedIndex(2);
            }
            
            //simulacion=u;
        }
    }
    
    public void setFormUsuarioPF(Tipoproducto u,Productosimulacion simu){
        if (u!=null){
            
            txtCodigoProd.setText(String.valueOf(u.getIdtipoproducto()));
            
            if(u.getNombre().equals("Paquete Normal"))
                u.setNombre("Galleta Soda Sbelt");
            if(u.getNombre().equals("Paquete Smile"))
                u.setNombre("Galleta Smile");
            if(u.getNombre().equals("Paquete Rellena"))
                u.setNombre("Galleta Super Rellenita");
  
            txtProducto.setText(u.getNombre());
            Integer cantProducida=simu.getCantProducida();
            Integer cantMerma=simu.getCantMerma();
            Integer cantidad=cantProducida+cantMerma;
            
            txtCantidad.setText(String.valueOf(cantidad));
            //txtCantidad.setText(u.getMaxPolitica().toString());
            
            
            //if(u.getTipo().equals("MP")){
                //cmbTurno.setSelectedIndex(0);
            //}
            //if(u.getTipo().equals("PF")){
              //  cmbTurno.setSelectedIndex(1);
            //}
            //if(u.getTipo().equals("PI")){
             //   cmbTurno.setSelectedIndex(2);
            //}
            
            tipoproducto=u;
        }
    }
    
    public JFrame getPadre(){ return padre; }
    
    public String getCantidad(){
        return txtCantidad.getText().trim();
    }
    
     public String getSimulacion(){
        return txtSimulacion.getText().trim();
    }
     
    public int getTurno(){
        return cmbTurno.getSelectedIndex();
    }

    
    
    public String getCodProd(){
        return txtCodigoProd.getText().trim();
    }
    
    public void setFecha(String fecha){
        txtFecha.setText(fecha);
    }
      
    

    
    public void mostrarAviso(String msn){
        Validaciones.mostrarMensajeAvisoVal(msn);   
    }
//    public void mostrarError(String msn){
//        Validaciones.mostrarMensajeErrorVal(msn);           
//    }
//    public int solicitarConfirmacion(String msn){
//        return Validaciones.solicitarConfirmacionVal(msn);
//    } 
    
    
    
    
  
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jRadioButton1 = new javax.swing.JRadioButton();
        jLabel7 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtProducto = new javax.swing.JTextField();
        btnGuardar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        txtCantidad = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cmbTurno = new javax.swing.JComboBox();
        btnBuscarP = new javax.swing.JButton();
        txtFecha = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtSimulacion = new javax.swing.JTextField();
        btnBuscarS = new javax.swing.JButton();
        txtCodigoProd = new javax.swing.JTextField();

        jRadioButton1.setText("jRadioButton1");

        jLabel7.setText("jLabel7");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Pedido Produccion");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos"));

        jLabel3.setText("Producto");

        txtProducto.setEnabled(false);
        txtProducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtProductoActionPerformed(evt);
            }
        });
        txtProducto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtProductoKeyTyped(evt);
            }
        });

        btnGuardar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/save.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.setBorderPainted(false);
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnCancelar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancel.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.setBorderPainted(false);
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        txtCantidad.setEnabled(false);
        txtCantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCantidadKeyTyped(evt);
            }
        });

        jLabel8.setText("Turno");

        jLabel9.setText("Cantidad");

        jLabel2.setText("Fecha");

        cmbTurno.setEnabled(false);

        btnBuscarP.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/buscarChico.png"))); // NOI18N
        btnBuscarP.setBorderPainted(false);

        txtFecha.setEnabled(false);

        jLabel1.setText("Simulacion");

        txtSimulacion.setEnabled(false);

        btnBuscarS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/buscarChico.png"))); // NOI18N
        btnBuscarS.setBorderPainted(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(338, Short.MAX_VALUE)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(196, 196, 196))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel9)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel8))
                .addGap(72, 72, 72)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnBuscarP)
                        .addGap(55, 55, 55)
                        .addComponent(txtCodigoProd, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(txtSimulacion)
                            .addGap(18, 18, 18)
                            .addComponent(btnBuscarS))
                        .addComponent(cmbTurno, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(167, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(txtSimulacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnBuscarS))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jLabel8))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(cmbTurno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel3)
                                        .addComponent(txtProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(5, 5, 5))
                                .addComponent(btnBuscarP))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(txtCodigoProd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnGuardar)
                            .addComponent(btnCancelar))))
                .addContainerGap(39, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 6, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtProductoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtProductoActionPerformed

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void txtProductoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProductoKeyTyped
        // TODO add your handling code here:
        String car = txtProducto.getText();
        if(car.length()>=50) evt.consume();        
        Validaciones.soloTexto(evt);  
        
    }//GEN-LAST:event_txtProductoKeyTyped

    private void txtCantidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCantidadKeyTyped
        // TODO add your handling code here:
        String car = txtCantidad.getText();
        if(car.length()>=5) evt.consume();        
        Validaciones.soloDigito(evt);
    }//GEN-LAST:event_txtCantidadKeyTyped

    public void llenaComboEstado(ArrayList<String> lista){
        if(lista!=null){
            for (String opc : lista){
                cmbTurno.addItem(opc);
            }
        }
    }
    
    public void llenaComboUnidades(ArrayList<String> lista){
        if(lista!=null){
            for (String opc : lista){
                cmbTurno.addItem(opc);
            }
        }
    }
    
    
   public void LimpiarDatos(){
        txtProducto.setText("");
        txtCantidad.setText("");
        cmbTurno.setSelectedItem(0);

    }
    
        
    public void addGuardarListener(ActionListener ml){
        this.btnGuardar.addActionListener(ml);
    }
    
    public void addBuscarPListener(ActionListener ml){
        this.btnBuscarP.addActionListener(ml);
    }
    
    public void addBuscarSListener(ActionListener ml){
        this.btnBuscarS.addActionListener(ml);
    }
    
    public void addCancelarListener(ActionListener ml){
        this.btnCancelar.addActionListener(ml);
    }     
    
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscarP;
    private javax.swing.JButton btnBuscarS;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JComboBox cmbTurno;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JTextField txtCantidad;
    private javax.swing.JTextField txtCodigoProd;
    private javax.swing.JTextField txtFecha;
    private javax.swing.JTextField txtProducto;
    private javax.swing.JTextField txtSimulacion;
    // End of variables declaration//GEN-END:variables
}
